package com.bdqn.BookManage.servlet;

import com.bdqn.BookManage.biz.BookInfoBiz;
import com.bdqn.BookManage.biz.BookTypeBiz;
import com.bdqn.BookManage.biz.impl.BookInfoBizImpl;
import com.bdqn.BookManage.biz.impl.BookTypeBizImpl;
import com.bdqn.BookManage.po.BookInfo;
import com.bdqn.BookManage.po.BookType;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * @author : CP
 * @version: 1.0
 * @program : BookManage
 * @description : 显示图书新增页面或修改页面处理器
 * @date : 2020-07-21 15:28
 **/
@WebServlet("/showJsp")
public class ShowJspServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /* 设置编码集 */
        resp.setCharacterEncoding("utf-8");
        req.setCharacterEncoding("utf-8");

        BookInfoBiz bookInfoBiz = new BookInfoBizImpl();

        String bookId = req.getParameter("bookId");

        if(bookId == null) {
            /* 新增页面跳转 */
            req.getRequestDispatcher("BookAdd.jsp").forward(req, resp);
        }else{
            /* 获取值 */
            BookInfo bookInfo = bookInfoBiz.querBookInfo(Integer.valueOf(bookId));
            req.setAttribute("bookInfo",bookInfo);
            /* 修改页面跳转 */
            req.getRequestDispatcher("BookUpdate.jsp").forward(req, resp);
        }
    }
}
